package com.benshou.bcss.common.trace.config;

import com.benshou.bcss.common.trace.TraceIdFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * 链路配置
 *
 * @author <a href="mailto:liuzhenbang@benshou.com">Liu Zhenbang</a>
 */
@Configuration
public class TraceConfig {

    /**
     * @return 链路追踪过滤器注册 Bean
     */
    @Bean
    public FilterRegistrationBean<TraceIdFilter> traceIdFilterRegistrationBean() {
        // 按最高优先级设置
        var registerBean = new FilterRegistrationBean<TraceIdFilter>();
        registerBean.setFilter(new TraceIdFilter());
        registerBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        registerBean.addUrlPatterns("/*");
        return registerBean;
    }
}
